﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.pbcatcolMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void pbcatcol_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            pbcatcolMgr mgr = new pbcatcolMgr();
            e.Total = int.Parse(mgr.GetRecordCount_pbcatcol(e.Parameters[pbcatcol_Filter.ParamPrefix]));
            IList<pbcatcol> list = mgr.FindAllByPage_pbcatcol(e.Start.ToString(), e.Limit.ToString(), e.Parameters[pbcatcol_Filter.ParamPrefix]);
            pbcatcol_MainStore.DataSource = list;
            pbcatcol_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            pbcatcolMgr mgr = new pbcatcolMgr();
            RowSelectionModel sm = pbcatcol_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                pbcatcol _pbcatcol = new pbcatcol();
                _pbcatcol.pbc_tnam = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_pbcatcol(_pbcatcol))
                {
                    log.Debug("pbcatcol中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            pbcatcol_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            pbcatcolMgr mgr = new pbcatcolMgr();
            pbcatcol _pbcatcol = new pbcatcol();
            if (Hid.Text.Length > 0)
                _pbcatcol = mgr.FindById_pbcatcol(int.Parse(Hid.Text));
            
			_pbcatcol.pbc_tid = int.Parse(TxtNumpbc_tid.Text.Trim());
			_pbcatcol.pbc_ownr = Txtpbc_ownr.Text.Trim();
			_pbcatcol.pbc_cnam = Txtpbc_cnam.Text.Trim();
			_pbcatcol.pbc_cid = Txtpbc_cid.Text.Trim();
			_pbcatcol.pbc_labl = Txtpbc_labl.Text.Trim();
			_pbcatcol.pbc_lpos = Txtpbc_lpos.Text.Trim();
			_pbcatcol.pbc_hdr = Txtpbc_hdr.Text.Trim();
			_pbcatcol.pbc_hpos = Txtpbc_hpos.Text.Trim();
			_pbcatcol.pbc_jtfy = Txtpbc_jtfy.Text.Trim();
			_pbcatcol.pbc_mask = Txtpbc_mask.Text.Trim();
			_pbcatcol.pbc_case = Txtpbc_case.Text.Trim();
			_pbcatcol.pbc_hght = Txtpbc_hght.Text.Trim();
			_pbcatcol.pbc_wdth = Txtpbc_wdth.Text.Trim();
			_pbcatcol.pbc_ptrn = Txtpbc_ptrn.Text.Trim();
			_pbcatcol.pbc_bmap = Txtpbc_bmap.Text.Trim();
			_pbcatcol.pbc_init = Txtpbc_init.Text.Trim();
			_pbcatcol.pbc_cmnt = Txtpbc_cmnt.Text.Trim();
			_pbcatcol.pbc_edit = Txtpbc_edit.Text.Trim();
			_pbcatcol.pbc_tag = Txtpbc_tag.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_pbcatcol(_pbcatcol);
            else
                isok = mgr.Add_pbcatcol(_pbcatcol);
            if (isok)
            {
                pbcatcol_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("pbcatcol中执行了保存（插入或修改），并成功");
                pbcatcol_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}